@extends('layouts.admin')

@section('title', '帖子回收站')

@section('css')
    <link rel="stylesheet" href="{{cdn('/supervise/assets/plugins/pines-notify/pnotify.css')}}">
@endsection

@section('content')
    <div class="static-content">
        <div class="page-content">
            <ol class="breadcrumb">
                <li class=""><a href="{{url('/admin')}}">Home</a></li>
                <li ><a href="{{url('/admin/topic')}}">Topic</a></li>
                <li class="active"><a href="{{url('/admin/topic/trash')}}">帖子回收站</a></li>
            </ol>
        </div>
        <div class="container-fluid">
            <div data-widget-group="group1" class="ui-sortable">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="panel panel-default" data-widget="{&quot;draggable&quot;: &quot;false&quot;}" data-widget-static="" style="visibility: visible; opacity: 1; display: block; transform: translateY(0px);">
                            <div class="panel-heading">
                                <h2>帖子列表</h2>
                                <div class="panel-ctrls" data-actions-container="" data-action-collapse="{&quot;target&quot;: &quot;.panel-body&quot;}">
                                </div>
                                <div class="options">
                                    <form method="get" action="{{url('/admin/topic/trash')}}" style="margin-bottom: 5px">
                                        <div class="form-group pull-right" style="margin-bottom: 0px">
                                            <div class="col-md-12">
                                                <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="fa fa-search"></i>
                                                    </span>
                                                    <input type="text" class="form-control" name="q" placeholder="搜索" value="{{$q or ''}}">
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="panel-body">
                                <table class="table m-n" id="table">
                                    <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>ID</th>
                                        <th>内容</th>
                                        <th>帖子</th>
                                        <th>发布者</th>
                                        <th>创建时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @if (!empty($replies))
                                        @foreach($replies as $replie)
                                            <tr>
                                                <td><input type="checkbox" data-replie-id="{{$replie->id or 0}}"></td>
                                                <td>{{$replie->id or 0}}</td>
                                                <td>
                                                    <div class="thread-title">
                                                        {{$replie->body_original or ''}}
                                                    </div>
                                                </td>
                                                <td><a href="{{url('/forum/topic')}}/{{$replie->topic->id or 0}}#reply{{$replie->index or 0}}">{{$replie->topic->title or ''}}</a></td>
                                                <td><a href="{{url('/user/info')}}/{{$replie->user->id or 0}}" target="_blank">{{$replie->user->name or ''}}</a></td>
                                                <td>{{dateTimeC($replie->created_at)}}前</td>
                                            </tr>
                                        @endforeach
                                    @endif
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="6">
                                            <div style="width: auto; margin: 10px" class="btn-group">
                                                <button class="btn btn-inverse-alt" id="all">全选</button>
                                                <button class="btn btn-inverse-alt" id="unckeck">反选</button>
                                                <button class="btn btn-inverse-alt" id="unall">取消</button>
                                                <button class="btn btn-inverse-alt" id="delete">删除</button>
                                            </div>
                                            <div class="pull-right">
                                                @if (!empty($p))
                                                    {{ $replies->appends(['p' => $p])->links() }}
                                                @else
                                                    {{ $replies->links() }}
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script src="{{cdn('/supervise/assets/plugins/pines-notify/pnotify.min.js')}}"></script>
    <script src="{{cdn('/supervise/assets/plugins/bootbox/bootbox.js')}}"></script> 	<!-- Bootbox -->
    <script>
        $table  = $('#table');
        $inputs = $('input', $table);
        $(document).ready(function () {
            $('#all').click(function () {
                $inputs.prop('checked', true);
            });
            $('#unall').click(function () {
                $inputs.prop('checked', false);
            });
            $('#unckeck').click(function () {
                $inputs = $('input', $table);
                $length = $inputs.length;
                for(var i = 0; i < $length; i++){
                    if ($($inputs[i]).prop('checked')){
                        $($inputs[i]).prop('checked', false);
                    }else{
                        $($inputs[i]).prop('checked', true);
                    }
                }
            });
            $('#delete').click(function () {
                $list = getIDList();
                if ($list.length <= 0){
                    return
                }
                bootbox.dialog({
                    message: "是否删除选择的项目",
                    title: "删除",
                    buttons: {
                        success: {
                            label: "删除",
                            className: "btn-success",
                            callback: function() {
                                postAction('delete', $list);
                            }
                        },
                        main: {
                            label: "取消",
                            className: "btn-primary",
                            callback: function() {
                            }
                        }
                    }
                });
            });
        });

        function postAction($action, $list) {
            $.post('/admin/reply/action',{
                _token:$('meta[name=csrf-token]').attr('content'),
                action:$action,
                ids:$list
            }, function (data) {
                if (data.code == 0){
                    window.location.reload();
                }else{
                    new PNotify({
                        title: 'Error!',
                        text: data.msg,
                        type: 'error',
                        hide: false,
                        icon: 'ti ti-info-alt',
                        styling: 'fontawesome'
                    });
                }
            });
        }
        function getIDList() {
            $inputs = $('input', $table);
            $length = $inputs.length;
            $list = [];
            for(var i = 0; i < $length; i++){
                if ($($inputs[i]).prop('checked')){
                    $list.push($($inputs[i]).attr('data-replie-id'));
                }
            }
            return $list;
        }
    </script>
@endsection